package com.gxuwz.business.action;

import org.springframework.beans.factory.annotation.Autowired;

import com.gxuwz.business.entity.Fee;
import com.gxuwz.business.service.IFeeService;
import com.gxuwz.business.service.IStudentService;
import com.gxuwz.util.Pager;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

import net.sf.json.JSONObject;

public class FeeAction extends BaseAction implements Preparable,ModelDriven<Fee>{

	private static final long serialVersionUID = 6154654121686438551L;
	private Fee fee;

	private static final String FEE_LIST = "/WEB-INF/page/fee/fee_list.jsp";
	private static final String FEE_ADD = "/WEB-INF/page/fee/fee_add.jsp";
	
	@Autowired
	private IFeeService feeService;
	@Autowired
	private IStudentService studentService;
	
	private String payFee;
	private Pager<Fee> feeList;

	public String getByPager(){
		feeList = feeService.getByPager(fee, page, limit);
		JsonData = JSONObject.fromObject(feeList);
		System.out.println(JsonData);
		return "JsonObject";
	}
	
	/**
	 * 缴费
	 * @return
	 */
	@SuppressWarnings("deprecation")
	public String pay(){
		try {
			Double payFees = Double.parseDouble(payFee);
			fee = feeService.findByRegId(fee.getRegId());
			//更新已缴费用
			Double feePut = fee.getFeePut()+payFees;
			fee.setFeePut(feePut);
			//更新待缴费用
			Double feeNeed = fee.getFeeNeed() - payFees;
			fee.setFeeNeed(feeNeed);

			if(fee.getFeeNeed() == 0){
				fee.setStatus(1);
			}else if(fee.getFeeNeed() < 0){
				fee.setStatus(2);
			}
			feeService.update(fee);
		} catch (Exception e) {
			e.printStackTrace();
		}
		jsonString = jsonToString(true);
		return "JsonString";
	}
	
	public String feeList(){
		forwardView = FEE_LIST;
		return SUCCESS;
	}
	
	public String openAdd(){
		forwardView = FEE_ADD;
		return SUCCESS;
	}
	
	@Override
	public Fee getModel() {
		return fee;
	}

	@Override
	public void prepare() throws Exception {
		if(null == fee){
			fee = new Fee();
		}
		
	}

	public String getPayFee() {
		return payFee;
	}

	public void setPayFee(String payFee) {
		this.payFee = payFee;
	}
	
	
	

}
